<%@page import="efrei.ngo.entity.User"%>
<%@page import="java.util.ArrayList"%>
<%@page import="efrei.ngo.util.DatabaseAccess"%>
<%@page import="efrei.ngo.util.GeneralUnil"%>
<%@page import="efrei.ngo.entity.ResourcePiece"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<%
User thisUser=(User)request.getSession().getAttribute("user");
if(thisUser==null){
	response.sendRedirect("WelcomePage.jsp");
	return;
}else{
	if(thisUser.getAuth()!='A'){
		response.getWriter().print("You don't have the authentication to this operation");
		return;
	}
}
%>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Resource Management</title>
<link rel="stylesheet" href="../css/button.css">
<link rel="stylesheet"
	href="../css/custom-theme/jquery-ui-1.8.18.custom.css">
<link rel="stylesheet" href="../css/custom-theme/jquery.ui.all.css">
<style>
#diaglocation {
	style: width:100%;
}

.tooltip {
	display: none;
	font-size: 12px;
	height: 70px;
	width: 160px;
	padding: 25px;
	color: #eee;
}
</style>
<script type="text/javascript" src="../js/jquery-1.7.1.js"></script>
<script type="text/javascript"
	src="../js/jquery-ui-1.8.18.custom.min.js"></script>
<script type="text/javascript"
	src="../js/external/jquery.bgiframe-2.1.2.js"></script>
<script type="text/javascript" src="../js/ui/jquery.ui.button.js"></script>
<script type="text/javascript" src="../js/ui/jquery.ui.core.js"></script>
<script type="text/javascript" src="../js/ui/jquery.ui.mouse.js"></script>
<script type="text/javascript" src="../js/ui/jquery.ui.widget.js"></script>
<script type="text/javascript" src="../js/ui/jquery.ui.dialog.js"></script>

<script type="text/javascript" src="../js/js4resourceMgm.js"></script>
<style type="text/css">
td.td_l_edge{
	border:0px;
    -moz-border-radius:0px 0px 0px 0px;
    -webkit-border-top-left-radius:5px;
    border-top-left-radius:5px;
    -moz-border-radius:0px 0px 0px 0px;
    -webkit-border-bottom-left-radius:5px;
    border-bottom-left-radius:5px;
	
	color:#FFF;
    
	background:-webkit-gradient(
        linear,
        left bottom,
        left top,
        color-stop(0.39, rgb(85,85,85)),
        color-stop(0.7, rgb(105,105,105))
        );
    background:-moz-linear-gradient(
        center bottom,
        rgb(85,85,85) 39%,
        rgb(105,105,105) 70%
        );
}

td.td_middle{
	
	color:#FFF;
    border:0px;
	background:-webkit-gradient(
        linear,
        left bottom,
        left top,
        color-stop(0.39, rgb(85,85,85)),
        color-stop(0.7, rgb(105,105,105))
        );
    background:-moz-linear-gradient(
        center bottom,
        rgb(85,85,85) 39%,
        rgb(105,105,105) 70%
        );
}
td.td_r_edge{
    -moz-border-radius:0px 0px 0px 0px;
    -webkit-border-top-right-radius:5px;
    border-top-right-radius:5px;
    -moz-border-radius:0px 0px 0px 0px;
    -webkit-border-bottom-right-radius:5px;
    border-bottom-right-radius:5px;
	
	color:#FFF;
    border:0px;
	background:-webkit-gradient(
        linear,
        left bottom,
        left top,
        color-stop(0.39, rgb(85,85,85)),
        color-stop(0.7, rgb(105,105,105))
        );
    background:-moz-linear-gradient(
        center bottom,
        rgb(85,85,85) 39%,
        rgb(105,105,105) 70%
        );
}

.table1 th {
	font: bold 11px "Trebuchet MS", Verdana, Arial, Helvetica,sans-serif;
	color:#FFF;
	border-right: 1px solid #C1DAD7;
	border-bottom: 1px solid #C1DAD7;
	border-top: 1px solid #C1DAD7;
	letter-spacing: 2px;
	text-transform: uppercase;
	text-align: left;
	padding: 6px 6px 6px 12px;
	background:#666 no-repeat;
}

.table1 td {
	border-right: 1px solid #C1DAD7;
	border-bottom: 1px solid #C1DAD7;
	background: #fff;
	font-size:15px;
	padding: 6px 6px 6px 12px;
}
</style>
</head>
<body onLoad="inital()">
	<!-- ---------------------------- -->
	<!----------------------------------->
	<!-- this is in the bump-up dialog -->
	<div id="dialog-form" title="Add New Resource" style="font-size: 12px">
		<form>
			<fieldset>
				<div align="center">
					<table width="100%">
						<tr>
							<td width="40%" align="right">Resource Name</td>
							<td width="60%"><input type="text" style="width: 100%"
								name="diagName" id="diagName"
								class="text ui-widget-content ui-corner-all" /></td>
						</tr>
						<tr>
							<td align="right">Type</td>
							<td><input type="text" style="width: 100%" name="diagType"
								id="diagType" value=""
								class="text ui-widget-content ui-corner-all" /></td>
						</tr>
						<tr>
							<td align="right">Country</td>
							<td><label for="diaglocation"></label> <%=GeneralUnil.getCountryListHTML("diaglocation")%>
							</td>
						</tr>
						<tr>
							<td align="right">City</td>
							<td><input type="text" name="diagCity" id="diagCity"
								style="width: 100%"></td>
						</tr>
						<tr>
							<td align="right">Quantity</td>
							<td><label for="diagQuan"></label> <input type="text"
								name="diagQuan" id="diagQuan" style="width: 100%"></td>
						</tr>
						<tr>
							<td align="right">Unit</td>
							<td><label for="diagUnit"></label> <input type="text"
								name="diagUnit" id="diagUnit" style="width: 100%"></td>
						</tr>
						<tr>
							<td align="right">Distribute Date</td>
							<td><label for="diagDate"></label> <input type="text"
								name="diagDate" id="diagDate" style="width: 100%" readonly></td>
						</tr>
					</table>
				</div>
			</fieldset>
		</form>
	</div>
	<!-- ---------------------------- -->
	<h2>Resouece Management</h2>
	<form name="form1" method="get" action="ResourceMgm.jsp">
		<div>
			<table width="100%" border="0">
				<tr>
					<td width="10%" class="td_l_edge" align="center">Filter Condition</td>
					<td width="20%" class="td_middle">Name <label> <input type="text"
							name="schName" id="schName">
					</label></td>
					<td width="20%" class="td_middle">Type <label> <%=GeneralUnil.getTypeListHTML("schType")%>
					</label></td>
					<td width="20%" class="td_middle">Continent <label> <%=GeneralUnil.getContinentListHTML("schCont")%>
					</label></td>
					<td width="20%" class="td_middle">Location <label> <%=GeneralUnil.getCountryListHTML("schLoc")%>
					</label></td>
					<td width="10%" align="center" valign="middle" class="td_r_edge"><input
						type="submit" name="btnSearch" id="btnSearch" value="Search">
						<input type="button" name="btnShowAll" id="btnShowAll"
						value="Show All" onClick="window.location.href='ResourceMgm.jsp'">
					</td>
				</tr>
			</table>
	</form>
	<h3>Here is the information</h3>
	<div align="right">
		<input type="button" onclick="onclick_newRS()" value="New Resource" />
	</div>
	<table width="100%" class="table1">
		<tr align="center">
			<th width="5%">Seq.</th>
			<th width="12%">Name</th>
			<th width="12%">Type</th>
			<th width="12%">Loca.</th>
			<th width="12%">Quant.</th>
			<th width="12%">Unit</th>
			<th width="12%">Date</th>
			<th>Oper.</th>
		</tr>
		<%
			String name = request.getParameter("schName");
			String type = request.getParameter("schType");
			String loc = request.getParameter("schLoc");
			String cont = request.getParameter("schCont");

			String sql = "SELECT id_rs,quantity,unit,lu_date,name,type,country,city FROM rslist,rstypelist,rsLocation WHERE rslist.id_type=rstypelist.id_type AND rslist.id_location=rsLocation.id_location";

			if (name != null && name != "") {
				sql += " AND name='" + name + "'";
			}
			if (type != null && type != "") {
				sql += " AND type='" + type + "'";
			}
			if (loc != null && loc != "") {
				sql += " AND country='" + loc + "'";
			}
			if (cont != null && cont != "") {
				sql += " AND continent='" + cont + "'";
			}

			DatabaseAccess.connectToDB();
			ArrayList<ResourcePiece> list = DatabaseAccess.dbGetRSList(sql);
			String listOFResource = "";
			ResourcePiece onePiece;
			System.out.println("there are " + list.size() + " Records.");
			for (int i = 0, len = list.size(); i < len; i++) {
				onePiece = list.get(i);
				listOFResource += "<tr><td>"
						+ (i + 1)
						+ "</td><td>"
						+ onePiece.getName()
						+ "</td><td>"
						+ onePiece.getType()
						+ "</td><td>"
						+ onePiece.getLocation()
						+ "."
						+ onePiece.getCity()
						+ "</td><td>"
						+ onePiece.getQuantity()
						+ "</td><td>"
						+ onePiece.getUnit()
						+ "</td><td>"
						+ onePiece.getDate()
						+ "</td><td><input type=\"text\" id=\"txt"+onePiece.getId_rs()+"\"><input type=\"button\" value=\" + \" onClick=\"onClick_edit('a',"
						+ onePiece.getId_rs() + ")\"><input type=\"button\" value=\" - \" onClick=\"onClick_edit('s',"
						+ onePiece.getId_rs() + ")\"></td></tr>";
			}
		%>
		<%=listOFResource%>
	</table>
	</div>
</body>
</html>